package com.leon.picture.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Set;

import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;

import com.leon.classify.domain.AdvertPic;
import com.leon.classify.domain.Company;
import com.leon.classify.domain.HeadAdvert;
import com.leon.classify.domain.HeadAdvertList;
import com.leon.classify.domain.LeftRecommon;
import com.leon.classify.domain.MiddleArea;
import com.leon.classify.domain.RightArea;
import com.leon.classify.domain.User;
import com.leon.classify.service.ClassifyService;
import com.leon.common.action.BaseAction;
import com.leon.common.util.VVMappingUtil;
import com.leon.module.service.ModuleService;
import com.leon.picture.service.PictureService;

public class PictureAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	private static final int BUFFER_SIZE = 16 * 1024 ;
	private ModuleService moduleService;
	private ClassifyService classifyService;
	private PictureService pictureService;
	private final static String SUCCESSMSG="{success:true}";
	private String uName;
	public ModuleService getModuleService() {
		return moduleService;
	}
	public void setModuleService(ModuleService moduleService) {
		this.moduleService = moduleService;
	}
	public ClassifyService getClassifyService() {
		return classifyService;
	}
	public void setClassifyService(ClassifyService classifyService) {
		this.classifyService = classifyService;
	}
	/**
	 * 试用response发送数据到HTML
	 * @param str
	 */
	public void sendMessage(String str){
		try {
			this.getResponse().getWriter().write(str);
			this.getResponse().getWriter().flush();
			this.getResponse().getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	//得到所有图片管理的列表
	public void getAllPicManage(){
		StringBuffer str=new StringBuffer("[");
		String leftstr=this.getLeftRec();
		String middlestr=this.getMiddleStr();
		String rightstr=this.getRightStr();
		String headstr=this.getHeadStr();
		String headPicstr=this.getHeadPic();
		String secondPicstr=this.getSecondRightPic();
		str.append(leftstr);
		str.append(","+middlestr);
		str.append(","+rightstr);
		str.append(","+headstr);
		str.append(","+headPicstr);
		str.append(","+secondPicstr);
		String uName=this.getRequest().getParameter("uName");
		if(uName.equals("root")){
			str.append(","+"{text:'用户管理',type:'user',leaf:true}");
		}
		str.append("]");
		this.sendMessage(str.toString());
	}
	//返回左列推荐的类别修改图片
	public String getLeftRec(){
		List<LeftRecommon>list=moduleService.getAllLeftRec();
		StringBuffer str=new StringBuffer("{text:'左列推荐'");
		if(list!=null&&list.size()>0){
			str.append(",children:[");
			for(LeftRecommon lr:list){
				str.append("{text:'"+lr.getAreaName()+"',id:'"+lr.getLeftRecommonId()+"',type:'left',leaf:true},");
			}
			str.deleteCharAt(str.length()-1);
			str.append("]");
		}else{
			str.append(",leaf:true");
		}
		str.append("}");
		return str.toString();
	}
	//返回中间的模块修改图片
	public String getMiddleStr(){
		StringBuffer str=new StringBuffer("{text:'中间模块'");
		List<MiddleArea>list=moduleService.getAllMiddle();
		if(list!=null && list.size()>0){
			str.append(",children:[");
			for(MiddleArea ma:list){
				str.append("{text:'"+ma.getAreaName()+"',id:'"+ma.getMiddleAreaId()+"',type:'middle',leaf:true},");
			}
			str.deleteCharAt(str.length()-1);
			str.append("]");
		}else{
			str.append(",leaf:true");
		}
		str.append("}");
		return str.toString();
	}
	//返回中间的模块修改图片
	public String getRightStr(){
		StringBuffer str=new StringBuffer("{text:'右边模块'");
		List<RightArea>list=moduleService.getAllRight();
		if(list!=null && list.size()>0){
			str.append(",children:[");
			for(RightArea ra:list){
				str.append("{text:'"+ra.getAreaName()+"',id:'"+ra.getRightAreaId()+"',type:'right',leaf:true},");
			}
			str.deleteCharAt(str.length()-1);
			str.append("]");
		}else{
			str.append(",leaf:true");
		}
		str.append("}");
		return str.toString();
	}
	//得到头部广告的列表
	public String getHeadStr(){
		StringBuffer str=new StringBuffer("{text:'头部广告明细',type:'ahead'");
		List<HeadAdvert>list=pictureService.getAllHeadAdvert();
		if(list!=null && list.size()>0){
			str.append(",children:[");
			for(HeadAdvert ha:list){
				if(ha.getLocation()==1){
					str.append("{text:'"+ha.getHeadName()+"(左)");
				}else if(ha.getLocation()==3){
					str.append("{text:'"+ha.getHeadName()+"(右)");
				}
				str.append("',id:'"+ha.getHeadAdvertId()+"',type:'head',leaf:true},");
			}
			str.deleteCharAt(str.length()-1);
			str.append("]");
		}else{
			str.append(",leaf:true");
		}
		str.append("}");
		return str.toString();
	}
	public String getHeadPic(){
		return "{text:'头部图片',type:'headPic',leaf:true}";
	}
	//二级页面右边的广告图片
	public String getSecondRightPic(){
		return "{text:'二级页面图片',type:'secondPic',leaf:true}";
	}
	//给左列推荐上传图片
	@SuppressWarnings("deprecation")
	public String uploadLeftRecPic(){
		String leftRecId=this.getRequest().getParameter("leftRecId");
		String picName=this.getRequest().getParameter("picName");
		//用于将图片关联到商家
		String companyId=this.getRequest().getParameter("companyId");
		Company company=classifyService.getCompany(companyId);
		LeftRecommon lr=moduleService.getLeftRecById(leftRecId);
		MultiPartRequestWrapper wrapper=(MultiPartRequestWrapper) this.getRequest();
		File[] file=wrapper.getFiles("fileName");
		BufferedInputStream in = null ;
		BufferedOutputStream out = null ;
		Date date=new Date();
		AdvertPic ap=new AdvertPic();
		ap.setLeftRecommon(lr);
		ap.setLocation(1);//用于过滤掉不在商家里显示
		Set<AdvertPic>aps=lr.getAdvertPics();
		try {
			for(int i=0;i<file.length;i++){
				 in = new BufferedInputStream( new FileInputStream(file[i]), BUFFER_SIZE);
				 out = new BufferedOutputStream( new FileOutputStream(new File(this.getRequest().getRealPath("/upload")+"/"+lr.getLeftRecommonId()+date.getTime()+".jpg")), BUFFER_SIZE);
                 byte [] buffer = new byte [BUFFER_SIZE];
                 while (in.read(buffer) > 0 ) {
                    out.write(buffer);
                 }
                 ap.setPicUrl("/upload/"+lr.getLeftRecommonId()+date.getTime()+".jpg");
                 ap.setPicName(picName);
                 ap.setCompany(company);
                 String displayOrder=this.getRequest().getParameter("displayOrder");
                 if(displayOrder.equals("")){
                	 displayOrder="1";
                 }
                 ap.setDisplayOrder(Integer.valueOf(displayOrder));
                 aps.add(ap);
                 lr.setAdvertPics(aps);
                 out.flush();
			}
			moduleService.createLeftRe(lr);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	//左列推荐的 所以图片广告
	public void getLeftRecPicList(){
		String leftRecId=this.getRequest().getParameter("leftRecId");
		LeftRecommon lr=moduleService.getLeftRecById(leftRecId);
		Set<AdvertPic>aps=lr.getAdvertPics();
		StringBuffer str=new StringBuffer("{root:[");
		if(aps!=null && aps.size()>0){
			for(AdvertPic ap:aps){
				str.append("{picName:'"+ap.getPicName()+"',picUrl:'"+ap.getPicUrl()+"',picId:'"+ap.getAdvertPicId()+"',displayOrder:'"+ap.getDisplayOrder()+"'},");
			}
			str.deleteCharAt(str.length()-1);
		}
		str.append("]}");
		this.sendMessage(str.toString());
	}
	//删除模块中的图片
	@SuppressWarnings("deprecation")
	public void deletePic(){
		String picId=this.getRequest().getParameter("picId");
		String type=this.getRequest().getParameter("type");
		AdvertPic ap=pictureService.getAdvertPicById(picId);
		String url=ap.getPicUrl();
		if(type.equals("left")){
			ap.setLeftRecommon(null);
		}else if(type.equals("middle")){
			ap.setMiddleArea(null);
		}else if(type.equals("right")){
			ap.setRightArea(null);
		}else if(type.equals("head")){
			ap.setLocation(null);
			/*ap.setPicUrl(null);
			ap.setPicName(null);*/
		}else if(type.equals("company")){
			ap.setCompany(null);
		}else if(type.equals("second")){
			ap.setLocation(null);
		}
		ap.setCompany(null);
		File file=new File(this.getRequest().getRealPath("")+url);
		file.delete();
		pictureService.createAdvertPic(ap);
		this.sendMessage(SUCCESSMSG);
	}
	public PictureService getPictureService() {
		return pictureService;
	}
	public void setPictureService(PictureService pictureService) {
		this.pictureService = pictureService;
	}
	//得到中间模块的图片
	public void getMiddleAreaPicList(){
		String middleAreaId=this.getRequest().getParameter("middleAreaId");
		MiddleArea ma=moduleService.getMiddleArea(middleAreaId);
		Set<AdvertPic>aps=ma.getAdvertPics();
		StringBuffer str=new StringBuffer("{root:[");
		if(aps!=null && aps.size()>0){
			for(AdvertPic ap:aps){
				str.append("{picName:'"+ap.getPicName()+"',picUrl:'"+ap.getPicUrl()+"',picId:'"+ap.getAdvertPicId()+"'},");
			}
			str.deleteCharAt(str.length()-1);
		}
		str.append("]}");
		this.sendMessage(str.toString());
	}
	//给中间模块上传图片
	@SuppressWarnings("deprecation")
	public String uploadMiddleAreaPic(){
		String middleAreaId=this.getRequest().getParameter("middleAreaId");
		String picName=this.getRequest().getParameter("picName");
		//用于将图片关联到商家
		String companyId=this.getRequest().getParameter("companyId");
		Company company=classifyService.getCompany(companyId);
		MiddleArea ma=moduleService.getMiddleArea(middleAreaId);
		MultiPartRequestWrapper wrapper=(MultiPartRequestWrapper) this.getRequest();
		File[] file=wrapper.getFiles("fileName");
		BufferedInputStream in = null ;
		BufferedOutputStream out = null ;
		Date date=new Date();
		AdvertPic ap=new AdvertPic();
		ap.setMiddleArea(ma);
		ap.setLocation(3);//用于过滤掉不在商家的图片组里显示
		Set<AdvertPic>aps=ma.getAdvertPics();
		try {
			for(int i=0;i<file.length;i++){
				 in = new BufferedInputStream( new FileInputStream(file[i]), BUFFER_SIZE);
				 out = new BufferedOutputStream( new FileOutputStream(new File(this.getRequest().getRealPath("/upload")+"/"+ma.getMiddleAreaId()+date.getTime()+".jpg")), BUFFER_SIZE);
                 byte [] buffer = new byte [BUFFER_SIZE];
                 while (in.read(buffer) > 0 ) {
                    out.write(buffer);
                 }
                 ap.setPicUrl("/upload/"+ma.getMiddleAreaId()+date.getTime()+".jpg");
                 ap.setPicName(picName);
                 ap.setCompany(company);
                 aps.add(ap);
                 ma.setAdvertPics(aps);
                 out.flush();
			}
			moduleService.createMiddleArea(ma);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	//得到右边模块的图片
	public void getRightAreaPicList(){
		String rightAreaId=this.getRequest().getParameter("rightAreaId");
		RightArea ra=moduleService.getRightAreaById(rightAreaId);
		Set<AdvertPic>aps=ra.getAdvertPics();
		StringBuffer str=new StringBuffer("{root:[");
		if(aps!=null && aps.size()>0){
			for(AdvertPic ap:aps){
				str.append("{picName:'"+ap.getPicName()+"',picUrl:'"+ap.getPicUrl()+"',picId:'"+ap.getAdvertPicId()+"'},");
			}
			str.deleteCharAt(str.length()-1);
		}
		str.append("]}");
		this.sendMessage(str.toString());
	}
	//给右边模块上传图片
	@SuppressWarnings("deprecation")
	public String uploadRightAreaPic(){
		String rightAreaId=this.getRequest().getParameter("rightAreaId");
		String picName=this.getRequest().getParameter("picName");
		//用于将图片关联到商家
		String companyId=this.getRequest().getParameter("companyId");
		Company company=classifyService.getCompany(companyId);
		RightArea ra=moduleService.getRightAreaById(rightAreaId);
		MultiPartRequestWrapper wrapper=(MultiPartRequestWrapper) this.getRequest();
		File[] file=wrapper.getFiles("fileName");
		BufferedInputStream in = null ;
		BufferedOutputStream out = null ;
		Date date=new Date();
		AdvertPic ap=new AdvertPic();
		ap.setLocation(4);//用于在商家的图片中过滤掉右边显示的图片
		ap.setRightArea(ra);
		Set<AdvertPic>aps=ra.getAdvertPics();
		try {
			for(int i=0;i<file.length;i++){
				 in = new BufferedInputStream( new FileInputStream(file[i]), BUFFER_SIZE);
				 out = new BufferedOutputStream( new FileOutputStream(new File(this.getRequest().getRealPath("/upload")+"/"+ra.getRightAreaId()+date.getTime()+".jpg")), BUFFER_SIZE);
                 byte [] buffer = new byte [BUFFER_SIZE];
                 while (in.read(buffer) > 0 ) {
                    out.write(buffer);
                 }
                 ap.setPicUrl("/upload/"+ra.getRightAreaId()+date.getTime()+".jpg");
                 ap.setCompany(company);
                 ap.setPicName(picName);
                 aps.add(ap);
                 ra.setAdvertPics(aps);
                 out.flush();
			}
			moduleService.createRightArea(ra);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	//存储一个头模块
	public void createHeadAd(){
		HeadAdvert ha;
		String headAdvertId=this.getRequest().getParameter("headAdvertId");
		if(headAdvertId.equals("")){
			ha=new HeadAdvert();
		}else{
			ha=pictureService.getHeadAdvertById(headAdvertId);
		}
		String headName=this.getRequest().getParameter("headName");
		String displayOrder=this.getRequest().getParameter("displayOrder");
		String state=this.getRequest().getParameter("state");
		String location=this.getRequest().getParameter("location");
		if(displayOrder.equals("")){
			displayOrder="1";
		}
		ha.setDisplayOrder(Integer.valueOf(displayOrder));
		ha.setHeadName(headName);
		ha.setLocation(Integer.valueOf(location));
		ha.setState(Integer.valueOf(state));
		pictureService.createHeadAd(ha);
		this.sendMessage(SUCCESSMSG);
	}
	//得到一个头部模块的列表
	public void getHeadAdvertList(){
		String headAdId=this.getRequest().getParameter("headAdId");
		HeadAdvert ha=pictureService.getHeadAdvertById(headAdId);
		StringBuffer str=new StringBuffer("{root:[");
		Set<HeadAdvertList> list=ha.getHeadAdvertLists();
		if(list.size()>0 && list!=null){
			for(HeadAdvertList hdl:list){
				str.append("{headAdvertId:'"+hdl.getHeadAdvertListId()+"',headAdvertName:'"+hdl.getAdvertName()+"',displayOrder:'"+hdl.getDisplayOrder()+"'},");
			}
			str.deleteCharAt(str.length()-1);
		}
		str.append("]}");
		this.sendMessage(str.toString());
	}
	//创建一个头部模块中的细项
	public void createHeadAdList(){
		String headAdId=this.getRequest().getParameter("headAdId");
		HeadAdvert ha=pictureService.getHeadAdvertById(headAdId);
		
		HeadAdvertList hal=new HeadAdvertList();
		String advertName=this.getRequest().getParameter("advertName");
		String advertDesc=this.getRequest().getParameter("advertDesc");
		
		String linkMan=this.getRequest().getParameter("linkMan");
		String phone=this.getRequest().getParameter("phone");
		String address=this.getRequest().getParameter("address");
		String busLine=this.getRequest().getParameter("busLine");
		String siteUrl=this.getRequest().getParameter("siteUrl");
		
		String displayOrder=this.getRequest().getParameter("displayOrder");
		String state=this.getRequest().getParameter("state");
		if(displayOrder.equals("")){
			displayOrder="1";
		}
		hal.setAdvertName(advertName);
		hal.setAdvertDesc(advertDesc);
		hal.setLinkMan(linkMan);
		hal.setPhone(phone);
		hal.setAddress(address);
		hal.setBusLine(busLine);
		hal.setSiteUrl(siteUrl);
		hal.setDisplayOrder(Integer.valueOf(displayOrder));
		hal.setState(Integer.valueOf(state));
		hal.setHeadAdvert(ha);
		pictureService.createHeadAdList(hal);
		this.sendMessage(SUCCESSMSG);
	}
	//删除一个头部广告明细
	public void deleteHeadAdList(){
		String headAdListId=this.getRequest().getParameter("headAdListId");
		HeadAdvertList hal=pictureService.getHeadAdvertListById(headAdListId);
		pictureService.delHeadAdList(hal);
		this.sendMessage(SUCCESSMSG);
	}
	//删除一个头部广告类
	public void deleteHeadAdvert(){
		String id=this.getRequest().getParameter("id");
		HeadAdvert ha=pictureService.getHeadAdvertById(id);
		pictureService.delHeadAdvert(ha);
		this.sendMessage(SUCCESSMSG);
	}
	//载入一个头部广告类
	public void loadHeadAdvert(){
		String id=this.getRequest().getParameter("id");
		HeadAdvert ha=pictureService.getHeadAdvertById(id);
		this.sendMessage("{sccess:true,data:["+VVMappingUtil.object2json(ha)+"]}");
	}
	//得到头部中间的图片
	public void getHeadAdvertPic(){
		StringBuffer str=new StringBuffer("{root:[");
		List <AdvertPic> aps=pictureService.getHeadAdvertPic();
		if(aps!=null && aps.size()>0){
			for(AdvertPic ap:aps){
				if(ap.getPicName()!=null &&ap.getPicUrl()!=null){
					str.append("{picName:'"+ap.getPicName()+"',picUrl:'"+ap.getPicUrl()+"',picId:'"+ap.getAdvertPicId()+"'},");
				}
			}
			str.deleteCharAt(str.length()-1);
		}
		str.append("]}");
		this.sendMessage(str.toString());
	}
	//给头部中间上传图片
	@SuppressWarnings("deprecation")
	public String uploadHeadAdvertPic(){
		String picName=this.getRequest().getParameter("picName");
		//用于将图片关联到商家
		String companyId=this.getRequest().getParameter("companyId");
		String displayValue=this.getRequest().getParameter("displayValue");
		Company company=classifyService.getCompany(companyId);
		MultiPartRequestWrapper wrapper=(MultiPartRequestWrapper) this.getRequest();
		File[] file=wrapper.getFiles("fileName");
		BufferedInputStream in = null ;
		BufferedOutputStream out = null ;
		Date date=new Date();
		AdvertPic ap=new AdvertPic();
		ap.setLocation(2);
		/*AdvertPic ap=pictureService.getHeadAdvertPicSingle();
		if(ap==null){
			ap=new AdvertPic();
			ap.setLocation(2);
		}*/
		try {
			for(int i=0;i<file.length;i++){
				 in = new BufferedInputStream( new FileInputStream(file[i]), BUFFER_SIZE);
				 out = new BufferedOutputStream( new FileOutputStream(new File(this.getRequest().getRealPath("/upload")+"/"+company.getCompanyId()+date.getTime()+".jpg")), BUFFER_SIZE);
                 byte [] buffer = new byte [BUFFER_SIZE];
                 while (in.read(buffer) > 0 ) {
                    out.write(buffer);
                 }
                 ap.setPicUrl("/upload/"+company.getCompanyId()+date.getTime()+".jpg");
                 ap.setPicName(picName);
                 ap.setCompany(company);
                 ap.setDisplayOrder(Integer.valueOf(displayValue));
                 System.out.println(ap.getCompany().getCompanyId());
                 out.flush();
			}
			pictureService.createAdvertPic(ap);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	@SuppressWarnings("deprecation")
	public String uploadSecondPic(){
		String picName=this.getRequest().getParameter("picName");
		//用于将图片关联到商家
		String companyId=this.getRequest().getParameter("companyId");
		Company company=classifyService.getCompany(companyId);
		MultiPartRequestWrapper wrapper=(MultiPartRequestWrapper) this.getRequest();
		File[] file=wrapper.getFiles("fileName");
		BufferedInputStream in = null ;
		BufferedOutputStream out = null ;
		Date date=new Date();
		AdvertPic ap=new AdvertPic();
		ap.setLocation(22);//用于过滤掉不在商家里显示
		try {
			for(int i=0;i<file.length;i++){
				 in = new BufferedInputStream( new FileInputStream(file[i]), BUFFER_SIZE);
				 out = new BufferedOutputStream( new FileOutputStream(new File(this.getRequest().getRealPath("/upload")+"/"+date.getTime()+".jpg")), BUFFER_SIZE);
                 byte [] buffer = new byte [BUFFER_SIZE];
                 while (in.read(buffer) > 0 ) {
                    out.write(buffer);
                 }
                 ap.setPicUrl("/upload/"+date.getTime()+".jpg");
                 ap.setPicName(picName);
                 ap.setCompany(company);
                 String displayOrder=this.getRequest().getParameter("displayOrder");
                 if(displayOrder.equals("")){
                	 displayOrder="1";
                 }
                 ap.setDisplayOrder(Integer.valueOf(displayOrder));
                 out.flush();
			}
			pictureService.createAdvertPic(ap);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	//二级页面右侧的图片广告
	public void getSecondPicList(){
		List<AdvertPic>aps=pictureService.getSecondPicList();
		StringBuffer str=new StringBuffer("{root:[");
		if(aps!=null && aps.size()>0){
			for(AdvertPic ap:aps){
				str.append("{picName:'"+ap.getPicName()+"',picUrl:'"+ap.getPicUrl()+"',picId:'"+ap.getAdvertPicId()+"',displayOrder:'"+ap.getDisplayOrder()+"'},");
			}
			str.deleteCharAt(str.length()-1);
		}
		str.append("]}");
		this.sendMessage(str.toString());
	}
	//得到所有用户
	public void getAllUser(){
		List<User> users=pictureService.getAllUser();
		StringBuffer str=new StringBuffer("{root:[");
		if(users!=null && users.size()>0){
			for(User user:users){
				str.append("{userName:'"+user.getUserName()+"',createDate:'"+user.getCreateDate()+"',userId:'"+user.getUserId()+"',phone:'"+user.getPhone()+"'},");
			}
			str.deleteCharAt(str.length()-1);
		}
		str.append("]}");
		this.sendMessage(str.toString());
	}
	//添加用户
	public void createUser(){
		User user = null;
		String userName=this.getRequest().getParameter("userName");
		String password=this.getRequest().getParameter("password");
		String sex=this.getRequest().getParameter("userSex");
		String userId=this.getRequest().getParameter("userId");
		String phone =this.getRequest().getParameter("phone");
		if (userId.equals("")||userId==null){
			user=new User();
		}else{
			user=pictureService.getUser(userId);
		}
		user.setCreateDate(new Date());
		user.setPassword(password);
		user.setUserName(userName);
		user.setPhone(phone);
		user.setUserSex(Integer.parseInt(sex));
		pictureService.createUser(user);
		this.sendMessage(SUCCESSMSG);
	}
	//删除用户
	public void deleteUser(){
		String userId=this.getRequest().getParameter("userId");
		User user=pictureService.getUser(userId);
		pictureService.deleteUser(user);
		this.sendMessage(SUCCESSMSG);
	}
	//加载一个
	public void loadUser(){
		String userId=this.getRequest().getParameter("userId");
		User user=pictureService.getUser(userId);
		String str=VVMappingUtil.object2json(user);
		this.sendMessage("{success:true,data:"+str+"}");
	}
	
	public String login(){
		String userName=this.getRequest().getParameter("userName");
		String password=this.getRequest().getParameter("password");
		User user=pictureService.getUserByName(userName,password);
		if(user!=null){
			uName=user.getUserName();
			return SUCCESS;
		}else{
			return "error";
		}
		
	}
	public String getUName() {
		return uName;
	}
	public void setUName(String name) {
		uName = name;
	}
}
